package com.nikmesoft.android.referendumfriend.adapters;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nikmesoft.android.referendumfriend.R;
import com.nikmesoft.android.referendumfriend.activities.Group_select;
import com.nikmesoft.android.referendumfriend.models.ItemHobies;
import com.nikmesoft.android.referendumfriend.models.item_hobby;
import com.nikmesoft.android.referendumfriend.models.person;
import com.nikmesoft.android.referendumfriend.utils.CommonUtil;

public class Group_select_adapter extends ArrayAdapter<ItemHobies> {
	private int resourceID;
	Context cont;

	public Group_select_adapter(Context context, int resourceID,
			List<ItemHobies> objects) {
		super(context, resourceID, objects);
		this.resourceID = resourceID;
		cont = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View row = convertView;

		if (row == null) {
			LayoutInflater inflater;
			inflater = (LayoutInflater) getContext().getSystemService(
					Context.LAYOUT_INFLATER_SERVICE);
			ItemHobies it = getItem(position);
			if (!it.isHaschild()) {
				row = inflater.inflate(R.layout.item_hobby2, null);
				TextView tx = (TextView) row.findViewById(R.id.tv_itemhobby2);
				tx.setText(it.getName());
			CheckBox cb=(CheckBox) row.findViewById(R.id.cb_itemhobby2);
			cb.setTag(it.getId());
			cb.setOnClickListener(new OnClickListener() {
				
				public void onClick(View v) {
					CheckBox cb=(CheckBox)v;
					if (cb.isChecked()) {
					String id=(String)cb.getTag();
					Group_select.id_hobby.add(Integer.parseInt(id));
					}
					else
					{
						Group_select.id_hobby.remove(Group_select.id_hobby.size()-1);
					}
					
				}
			});
			} else {
				row = inflater.inflate(this.resourceID, null);
				TextView tx = (TextView) row.findViewById(R.id.title_hobby);
				tx.setText(it.getName());
			}

		} else {
			row = convertView;
		}
		return row;

	}

}
